home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat5 / gp_overflow.z / gp_overflow
Encoding:
Text File  |  1998-10-30  |  16.8 KB  |  397 lines

  1.  
  2.  
  3.  
  4. ggggpppp____oooovvvveeeerrrrfffflllloooowwww((((5555))))                                                  ggggpppp____oooovvvveeeerrrrfffflllloooowwww((((5555))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      gp_overflow - GP Overflow Errors
  10.  
  11. TTTTOOOOPPPPIIIICCCC
  12.      This man page is intended to describe the underlying causes of and
  13.      possible solutions for overflowing the gp-relative area in the linker.
  14.  
  15. TTTThhhheeee SSSSyyyymmmmppppttttoooommmmssss aaaannnndddd aaaa SSSSiiiimmmmpppplllleeee SSSSoooolllluuuuttttiiiioooonnnn
  16.      GP overflow is reported by the linker with one of several error messages:
  17.  
  18.          GP-relative sections overflow by 0x??? bytes.  Please recompile with
  19.          a smaller -G value.
  20.  
  21.          GOT overflow: please relink with -multigot.
  22.  
  23.          GOT unreachable: please relink with -multigot.
  24.  
  25.      These messages all indicate that the code being linked contains more than
  26.      64KB of GP-relative data area (see the next section), and attempts to
  27.      reference it with a signed 16-bit displacement from the GP register.
  28.  
  29.      In the past we recommended recompiling with -xgot. Although this
  30.      generally solved the GP overflow problem it created larger, slower
  31.      programs.  We developed ----mmmmuuuullllttttiiiiggggooootttt to create multiple GOTs during linking:
  32.      ----mmmmuuuullllttttiiiiggggooootttt prevents the GOT overflow problem while retaining the more
  33.      efficient GP relative code. -xgot will be dropped in future releases.
  34.      The preferred solution to the problem is to use the ----mmmmuuuullllttttiiiiggggooootttt option to
  35.      _l_d.  At some point ----mmmmuuuullllttttiiiiggggooootttt is likely to become the default default.
  36.  
  37.      Even with ----mmmmuuuullllttttiiiiggggooootttt one must still avoid having too much GP data:  if the
  38.      ----GGGG value is greater than zero it may be necessary to use a smaller ----GGGG
  39.      value (see below for definitions).
  40.  
  41. TTTTeeeerrrrmmmmiiiinnnnoooollllooooggggyyyy
  42.      GGGGPPPP   GP (sometimes spelled gp) is a register in the register set of the
  43.           processor.  It used in a consistent way by the software.  The
  44.           register is actually an ordinary integer register (register 28) but
  45.           by software convention it is used only in a stylized way.  The GP-
  46.           area is a region of memory addressable by an offset of the GP
  47.           register. See the section "Underlying Mechanisms" below.
  48.  
  49.      GGGGOOOOTTTT  To provide Position Independent Code (PIC) which can be relocated
  50.           without modifying the text of the program (or DSO) it is sufficient
  51.           to have a data table with the actual addresses of global data (with
  52.           appropriate code generation and linking support).  This data table
  53.           is constructed by _l_d(1) and is called the Global Offset Table (GOT).
  54.           For a further explanation of what the GOT is, see _d_s_o(5).
  55.  
  56.      PPPPIIIICCCC  Position Independent Code (PIC) is, as mentioned above, a method of
  57.           code generation which results in code that can be shared by multiple
  58.           users (each program must have its own data space! Code sharing and
  59.           independent data is arranged automatically by the compilation and
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. ggggpppp____oooovvvveeeerrrrfffflllloooowwww((((5555))))                                                  ggggpppp____oooovvvveeeerrrrfffflllloooowwww((((5555))))
  71.  
  72.  
  73.  
  74.           run-time systems).  For details on PIC code generation, see the
  75.           _d_s_o(5) (for old-32bit-abi) or the "MIPSpro N32 ABI Handbook" (for
  76.           the new-32bit-abi).
  77.  
  78.      ----GGGG  nnnn
  79.           This compiler option sets the ----GGGG value, _n.  This compiler option
  80.           affects how much data goes into the "small data" and "small bss" and
  81.           other areas (discussed in the "Underlying Mechanisms" section below
  82.           where _s_h_o_r_t _d_a_t_a _s_e_g_m_e_n_t is defined) ).  The default _n for old-
  83.           32bit-abi compilation (when producing PIC code) is 0.  The default
  84.           for new-32bit-abi and 64bit-abi compilation is 8.  To see the value
  85.           actually in use, use the -_s_h_o_w option on the compilation line and
  86.           check the ----GGGG option actually passed to the compiler passes.
  87.  
  88. UUUUnnnnddddeeeerrrrllllyyyyiiiinnnngggg MMMMeeeecccchhhhaaaannnniiiissssmmmmssss
  89.      The MIPS instruction set architecture provides instructions for loading
  90.      values from memory, and storing values to memory, which calculate an
  91.      effective address by adding the content of a register to a signed 16-bit
  92.      immediate value (displacement) in the instruction.
  93.  
  94.      The compilers take advantage of this capability by maintaining various
  95.      frequently-used data objects in a number of small memory sections,
  96.      keeping a pointer to this area of memory in a dedicated register (GP),
  97.      and generating references to those objects as simple load/store
  98.      instructions with signed 16-bit displacements If the total size of these
  99.      memory sections exceeds 64K bytes, the displacements in some of those
  100.      instructions will likely overflow, and the linker reports a GP overflow
  101.      error.
  102.  
  103.      We will refer to these small GP-relative memory sections collectively as
  104.      the _s_h_o_r_t _d_a_t_a _s_e_g_m_e_n_t below. In general, it is comprised of the Unix
  105.      sections .sdata, .sbss, The data objects placed in the short data segment
  106.      by the compiler and linker include:
  107.  
  108.      Static data page pointers:
  109.          These are no longer a problem with current code generation and
  110.          linkers.
  111.  
  112.      GOT pointers:
  113.          References to static data or subroutine addresses in shared code,
  114.          except for those which use page pointers mentioned above, normally
  115.          load an address from the GOT, relative to GP, and use it for the
  116.          access. By default, these address loads assume an offset from GP of
  117.          32KB or less. Using the -multigot linker option tells the linker to
  118.          arrange for as many GOTs as needed in the a.out or DSO (so the fact
  119.          each GOT is limited in size becomes irrelevant).  Using the (now
  120.          deprecated) -xgot compiler option (or -TENV:large_GOT option when
  121.          compiling n32 or 64-bit programs using the MIPSPro compiler) forces
  122.          the compiler to assume full 32-bit offsets from GP, and thereby
  123.          eliminates the restriction that these pointers fit in 64KB.
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. ggggpppp____oooovvvveeeerrrrfffflllloooowwww((((5555))))                                                  ggggpppp____oooovvvveeeerrrrfffflllloooowwww((((5555))))
  137.  
  138.  
  139.  
  140.      Small data objects:
  141.          The compiler attempts to place small data objects in a GP-relative
  142.          section (e.g. .sdata or .sbss or .lit4 or .lit8) and to reference
  143.          them directly using a signed 16-bit displacement.  The limit on the
  144.          size of objects treated this way can be changed from the default to nnnn
  145.          bytes by using the -G nnnn option These options must be used
  146.          consistently for all compilations in a given program or linker errors
  147.          will occur. You might get one of these errors:
  148.  
  149.          "foo" used in bar.o and baz.o has different sizes.
  150.  
  151.          "foo" used as gp-relative in bar.o and defined otherwise in baz.o.
  152.  
  153.          "foo" cannot be turned into gp-relative.
  154.  
  155.           The data objects affected by -G nnnn are numeric literals, addresses
  156.           including those generated by the compiler, all C static variables,
  157.           and (if the "-static"flag was used) FORTRAN local variables.
  158.  
  159.      Small literal objects:
  160.          The compiler also attempts to place small literal objects (e.g.
  161.          integer constants, floating point constants, addresses) in a GP-
  162.          relative section (e.g. .lit4, .lit8, or .srdata) and to reference
  163.          them directly using a signed 16-bit displacement.  The limit on the
  164.          size of literal objects treated this way can be changed from the
  165.          default to nnnn bytes by using the -G nnnn option.  The -G option must be
  166.          used consistently for all compilations in a given program, or linker
  167.          errors are likely to occur.
  168.  
  169.      Each of these uses normally has a positive effect on program performance.
  170.      (In fact, performance can often be improved further by increasing the
  171.      sizes of data and literal objects allocated to the short sections.)
  172.      However, if the total size of the four categories exceeds 64KB, the
  173.      linker will report GP overflow errors, and the program must be rebuilt to
  174.      shrink the total size of GP-relative data.
  175.  
  176. TTTTaaaaiiiilllloooorrrriiiinnnngggg aaaa SSSSoooolllluuuuttttiiiioooonnnn ffffoooorrrr BBBBeeeesssstttt PPPPeeeerrrrffffoooorrrrmmmmaaaannnncccceeee
  177.      The simplest solution is to use the -multigot option.  Finding the best
  178.      solution requires identifying the sizes of the short data section
  179.      components (page pointers, GOT pointers, small data, and small literals),
  180.      and removing only as much as necessary.  With this release this
  181.      information may be obtained from the linker by specifying the flag "-
  182.      gpinfo" directly to ld(1), or by specifying "-Wl,-gpinfo" to cc(1) or
  183.      f77(1).  In other cases, this information may be obtained by specifying
  184.      the "-m -aoutkeep" flags to ld(1) (or -Wl,-m,-aoutkeep to cc(1) or CC(1)
  185.      or f77(1)) and subsequently searching the load map for the desired
  186.      sections.
  187.  
  188.      Each of these components can be controlled:
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. ggggpppp____oooovvvveeeerrrrfffflllloooowwww((((5555))))                                                  ggggpppp____oooovvvveeeerrrrfffflllloooowwww((((5555))))
  203.  
  204.  
  205.  
  206.      Page pointers:
  207.          They are no longer an issue: compiler and linker changes now make the
  208.          the -TENV:no_page_offset option unnecessary.
  209.  
  210.      GOT pointers:
  211.          These must be GP-relative, but compiling with -multigot enables the
  212.          use of multiple gp regions and the linker will place the short data
  213.          and literal sections closer to an appropriate GP so that they can
  214.          still benefit.
  215.  
  216.      Small data:
  217.          Compiling with -G nnnn for nnnn smaller than the existing value shrinks
  218.          these sections.  Use ----GGGG 0000 to eliminate all GP-relative small data
  219.          references.  (Note that some small data references will be replaced
  220.          by new GOT pointer references, so the savings might not be as large
  221.          as the original size of the short data sections.)  Recompiling with
  222.          this option requires recompiling the entire program with it.
  223.  
  224.      Small literals:
  225.          Compiling with -G nnnn for nnnn smaller, shrinks these sections.  Use ----GGGG 0000
  226.          to eliminate all GP-relative small literal references.  (Note that
  227.          some small literal references will be replaced by new GOT pointer
  228.          references, so the savings might not be as large as the original size
  229.          of the short literal sections.)  Recompiling with -G nnnn requires
  230.          recompiling the entire program with it.
  231.  
  232.      There is another option which may perform better than the above.  The
  233.      main program and each DSO it uses each get their own short data segments.
  234.      Breaking parts of the program into separate DSOs may shrink all of the
  235.      short data segment components enough that the defaults work for some or
  236.      all of the pieces. However, be aware that subprogram calls which cross
  237.      DSO boundaries incur some extra overhead, so this solution is likely to
  238.      help performance only if the division can be made such that such
  239.      crossings are infrequent.
  240.  
  241. TTTThhhheeee ----xxxxggggooootttt ooooppppttttiiiioooonnnn
  242.      The following is retained to help make clear what the options used with
  243.      -xgot were so you can remove them and use -multigot instead.  Please do
  244.      not use -xgot.  Use -multigot. -multigot requires no recompiling, just
  245.      relinking.  (Any program compiled -xgot should be completely recompiled
  246.      to use -multigot.)  In the future -multigot will be on by default.
  247.  
  248.      The -xgot rules suggested for the earlier compiler releases were as
  249.      follows:
  250.  
  251.      For n32 or 64-bit programs, recompile everything in one's program with
  252.      the options:
  253.  
  254.          ----aaaavvvvooooiiiidddd____ggggpppp____oooovvvveeeerrrrfffflllloooowwww
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. ggggpppp____oooovvvveeeerrrrfffflllloooowwww((((5555))))                                                  ggggpppp____oooovvvveeeerrrrfffflllloooowwww((((5555))))
  269.  
  270.  
  271.  
  272.      this eliminates the problem. This flag is a synonym for
  273.  
  274.          ----GGGG 0000 ----xxxxggggooootttt ----TTTTEEEENNNNVVVV::::nnnnoooo____ppppaaaaggggeeee____ooooffffffffsssseeeetttt
  275.  
  276.      Programs compiled for the old 32bit abi recompile with
  277.  
  278.          ----GGGG 0000 ----xxxxggggooootttt
  279.  
  280.      ----xxxxggggooootttt is likely to have a significant negative impact on the program's
  281.      performance.
  282.  
  283. BBBBUUUUGGGGSSSS
  284.      _l_d earlier than IRIX 6.2 produced one page pointer per 64KB page of
  285.      static data, whether or not that page is ever referenced. As a result,
  286.      256MB of static data would fill the GP-relative area with page pointers,
  287.      leaving no space for the other GP-relative memory sections. More than
  288.      that would normally cause linker errors unless the -TENV:no_page_offset
  289.      option was used for compilation. The 6.2 and later linkers are much more
  290.      efficient in its data GOT page production making the option
  291.      -TENV:no_page_offset unnecessary.
  292.  
  293.      A workaround for this problem was to compile all large data blocks from
  294.      files which contain no programs of any kind, and link them into a
  295.      separate data-only dso. Since it contains no code, there will be no
  296.      references to the overflowed GOT. This dso can then be linked against
  297.      when building the main program. Since references to it are always via the
  298.      name of the symbol (or the name of the common in FORTRAN), the data will
  299.      be referenced correctly, but since the data is defined in a dso, space
  300.      will not be allocated in the main program.
  301.  
  302.      For example, suppose we wanted to define an array of 1,000,000,000
  303.      floating point values. We could then write the following source file in
  304.      C:
  305.  
  306.          float bigarray[1000000000];
  307.  
  308.      And subsequently compile it and link it thus:
  309.  
  310.          cc -c bigarray.c ld -shared bigarray.o -o bigarray.so
  311.  
  312.      Then we would link the main program thus:
  313.  
  314.          cc <objects> bigarray.so <libraries>
  315.  
  316.      To run it we must either install bigarray.so into /usr/lib, or else tell
  317.      the runtime linker rld(1) where to find it. One way of doing this is
  318.      setting the environment variable LD_LIBRARY_PATH to the pathname of the
  319.      directory in which bigarray.so can be found.
  320.  
  321.      FORTRAN programmers use the source file
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. ggggpppp____oooovvvveeeerrrrfffflllloooowwww((((5555))))                                                  ggggpppp____oooovvvveeeerrrrfffflllloooowwww((((5555))))
  335.  
  336.  
  337.  
  338.          BLOCKDATA DUMMY
  339.  
  340.          COMMON/mycom/bigarray(1000000000)
  341.  
  342.          END
  343.  
  344.      Compile it with f77(1), rather than with cc(1), the other steps are the
  345.      same.
  346.  
  347. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  348.      cc(1), f77(1), ld(1), dso(5), MIPSpro N32 ABI Handbook
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.